package com.example.demo.service.impl;

import java.util.List;

import com.example.demo.entity.Category;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.demo.mapper.GoodsMapper;
import com.example.demo.entity.Goods;
import com.example.demo.service.IGoodsService;

/**
 * 商品Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-03
 */
@Service
public class GoodsServiceImpl implements IGoodsService 
{
    @Autowired
    private GoodsMapper goodsMapper;

    /**
     * 查询商品
     * 
     * @param gid 商品主键
     * @return 商品
     */
    @Override
    public Goods selectGoodsByGid(Long gid)
    {
        return goodsMapper.selectGoodsByGid(gid);
    }
    @Override
    public Goods selectGoodsByCid(Long cid)
    {
        return goodsMapper.selectGoodsByCid(cid);
    }

    /**
     * 查询商品列表
     * 
     * @param goods 商品
     * @return 商品
     */
    @Override
    public List<Goods> selectGoodsList1(Goods goods)
    {
        List<Goods> list=goodsMapper.selectGoodsList(goods);

        return list;
    }
    @Override
    public PageResult selectGoodsList(Goods goods, int pageNum, int pageSize)
    {
        List<Goods> list=goodsMapper.selectGoodsList(goods);
        PageInfo<Goods> pageInfo =new PageInfo<>(list);
        PageResult pageResult= PageUtils.getPageResult(pageInfo);
        return pageResult;
    }

    /**
     * 新增商品
     * 
     * @param goods 商品
     * @return 结果
     */
    @Override
    public int insertGoods(Goods goods)
    {
        return goodsMapper.insertGoods(goods);
    }

    /**
     * 修改商品
     * 
     * @param goods 商品
     * @return 结果
     */
    @Override
    public int updateGoods(Goods goods)
    {
        return goodsMapper.updateGoods(goods);
    }

    /**
     * 批量删除商品
     * 
     * @param gids 需要删除的商品主键
     * @return 结果
     */
    @Override
    public int deleteGoodsByGids(Long[] gids)
    {
        return goodsMapper.deleteGoodsByGids(gids);
    }

    /**
     * 删除商品信息
     * 
     * @param gid 商品主键
     * @return 结果
     */
    @Override
    public int deleteGoodsByGid(Long gid)
    {
        return goodsMapper.deleteGoodsByGid(gid);
    }
}
